from model import model
from model.ArticleSearchIndex import Search
from services import MyCache


class searchDao:

    cache = MyCache().fsession()
    # 搜索
    @cache.memoize(tag="article-search")
    def search(self, keyword):
        result = []
        searchlist = Search().search(keyword)
        for search in searchlist:
            art = model.article.objects(id=search)
            if len(art) > 0:
                result.append(art.get())
        return result

    @staticmethod
    def clear():
        Search.clear()
